#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# File-Name:	survey-recoding-functions-PL.R
# Date:	October 4, 2021
# Author: Bernhard Clemm 
# Purpose: Contains functions to be used at beginning of analysis of PL surveys

# Variables are recoded/renamed according to codebook:
## https://docs.google.com/spreadsheets/d/1XGi3FluO304Sjd8AS9JjF2tHpjrplBd9EDlMziyPu9s/edit#gid=1932063479

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# PACKAGES
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

library(tidyverse)

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# W1 recoding ####
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

recode_PL_w1 <- function(data) {
  
  data <- data %>%
    
    # Age
    mutate(
      year_h1_r1 = as.numeric(gsub(" lat| lata", "", .$year_h1_r1))) %>%
    
    # perceived polarization
    mutate(
      perconflict_w1 = case_when(
        is.na(q58_2_r1) ~ q58_2b_r6,
        is.na(q58_2b_r6) ~ q58_2_r1),
      perpol_1_w1 = case_when(
        is.na(q58_2_r2) ~ q58_2b_r2,
        is.na(q58_2b_r2) ~ q58_2_r2,
        is.na(q58_2b_r2) & is.na(q58_2_r2) ~ q58_2b_r2),
      perpol_2_w1 = case_when(
        is.na(q58_2_r3) ~ q58_2b_r3,
        is.na(q58_2b_r3) ~ q58_2_r3,
        is.na(q58_2b_r3) & is.na(q58_2_r3) ~ q58_2b_r3),
      perpol_3_w1 = case_when(
        is.na(q58_2_r4) ~ q58_2b_r4,
        is.na(q58_2b_r4) ~ q58_2_r4,
        is.na(q58_2b_r4) & is.na(q58_2_r4) ~ q58_2b_r4),
      perpol_4_w1 = case_when(
        is.na(q58_2_r5) ~ q58_2b_r5,
        is.na(q58_2b_r5) ~ q58_2_r5,
        is.na(q58_2b_r5) & is.na(q58_2_r5) ~ q58_2b_r5)) %>%
    
    # Conflict condition: treatment if statement at the beginning of battery
    mutate(conflict_condition = case_when(
      !is.na(q58_2_r1) ~ "treatment",
      !is.na(q58_2b_r6) ~ "control")) %>%
    
    # Rename variables according to Codebook
    dplyr::rename(
        'respondent_id_w1' = respondent_id,
        'external_id_w1' = external_id,
        'start_date_w1' = survey_start_time,
        'end_date_w1' = survey_finish_time,
        'intro_w1' = intro2,
        'gender_w1' = sex,
        'age_cat_w1' = age,
        'age_w1' = year_h1_r1,
        'density_w1' = miasta,
        'edu_w1' = wyksztalcenie,
        'follow_w1' = q1,
        'wh_id_w1' = wejsciedowebhistorian_r1,
        'big5_1_w1' = q59_r1,
        'big5_2_w1' = q59_r2,
        'big5_3_w1' = q59_r3,
        'big5_4_w1' = q59_r4,
        'big5_5_w1' = q59_r5,
        'big5_6_w1' = q59_r6,
        'big5_7_w1' = q59_r7,
        'big5_8_w1' = q59_r8,
        'big5_9_w1' = q59_r9,
        'big5_10_w1' = q59_r10,
        'empathy_1_w1' = q60_r1,
        'empathy_2_w1' = q60_r2,
        'empathy_3_w1' = q60_r3,
        'empathy_4_w1' = q60_r4,
        'ideo_w1' = q2_r1,
        'gov_suppopp_w1' = q2dwa_r1,
        'gov_opp_1_w1' = q3_1_h1_r1,
        'gov_opp_2_w1' = q3_1_h1_r2,
        'gov_opp_3_w1' = q3_1_h1_r3,
        'gov_opp_4_w1' = q3_1_h1_r4,
        'gov_supp_1_w1' = q3_2_h1_r1,
        'gov_supp_2_w1' = q3_2_h1_r2,
        'gov_supp_3_w1' = q3_2_h1_r3,
        'gov_supp_4_w1' = q3_2_h1_r4,
        'gov_ind_1_w1' = q3_3_h1_r1,
        'gov_ind_2_w1' = q3_3_h1_r2,
        'gov_ind_3_w1' = q3_3_h1_r3,
        'gov_ind_4_w1' = q3_3_h1_r4,
        'party_w1' = q4pref,
        'party_closeness_w1' = q4prefjakbliska,
        'party_opp_w1' = q4niepref,
        'perception_ideo_right_w1' = q5a,
        'perception_ideo_left_w1' = q5b,
        'days_week_tv_w1' = q8_h2_r1,
        'days_week_print_w1' = q8_h2_r2,
        'days_week_radio_w1' = q8_h2_r3,
        'days_week_web_w1' = q8_h2_r4,
        'days_week_sm_w1' = q8_h2_r5,
        'days_week_msg_w1' = q8_h2_r6,
        'days_week_f2f_w1' = q8_h2_r7,
        'days_week_app_w1' = q8_h2_r8,
        'days_week_search_w1' = q8_h2_r9,
        'print_fgc_w1' = q9_r1,
        'print_se_w1' = q9_r2,
        'print_gw_w1' = q9_r3,
        'print_rzeczpospolita_w1' = q9_r4,
        'print_dgp_w1' = q9_r5,
        'print_gPC_w1' = q9_r6,
        'print_nd_w1' = q9_r7,
        'print_dt_w1' = q9_r8,
        'print_local_w1' = q9_r10,
        'print_polityka_w1' = q9_r11,
        'print_sieci_w1' = q9_r12,
        'print_np_w1' = q9_r13,
        'print_tdR_w1' = q9_r14,
        'print_tp_w1' = q9_r15,
        'print_gp_w1' = q9_r16,
        'print_wprost_w1' = q9_r17,
        'print_przegląd_w1' = q9_r18,
        'print_ta_w1' = q9_r19,
        'print_nie_w1' = q9_r20,
        'print_gn_w1' = q9_r21,
        'print_forum_w1' = q9_r22,
        'print_nc_w1' = q9_r23,
        'print_przekrój_w1' = q9_r25,
        'print_forbes_w1' = q9_r26,
        'print_press_w1' = q9_r27,
        'print_other_w1' = q9_r28,
        'print_other_text1_w1' = q9inne_h1_r1,
        'print_other_text2_w1' = q9inne_h1_r2,
        'print_other_text3_w1' = q9inne_h1_r3,
        'print_other_text4_w1' = q9inne_h1_r4,
        'print_other_text5_w1' = q9inne_h1_r5,
        'print_days_fgc_w1' = q10_h1_r1,
        'print_days_se_w1' = q10_h1_r2,
        'print_days_gw_w1' = q10_h1_r3,
        'print_days_rzeczpospolita_w1' = q10_h1_r4,
        'print_days_dgp_w1' = q10_h1_r5,
        'print_days_gpc_w1' = q10_h1_r6,
        'print_days_nd_w1' = q10_h1_r7,
        'print_days_dt_w1' = q10_h1_r8,
        'print_days_local_w1' = q10_h1_r10,
        'print_days_polityka_w1' = q10_h1_r11,
        'print_days_sieci_w1' = q10_h1_r12,
        'print_days_np_w1' = q10_h1_r13,
        'print_days_tdR_w1' = q10_h1_r14,
        'print_days_tp_w1' = q10_h1_r15,
        'print_days_gp_w1' = q10_h1_r16,
        'print_days_wprost_w1' = q10_h1_r17,
        'print_days_przegląd_w1' = q10_h1_r18,
        'print_days_ta_w1' = q10_h1_r19,
        'print_days_nie_w1' = q10_h1_r20,
        'print_days_gn_w1' = q10_h1_r21,
        'print_days_forum_w1' = q10_h1_r22,
        'print_days_nc_w1' = q10_h1_r23,
        'print_days_Przekrój_w1' = q10_h1_r25,
        'print_days_Forbes_w1' = q10_h1_r26,
        'print_days_Press_w1' = q10_h1_r27,
        'print_days_other1_w1' = q10_h1_r28,
        'print_days_other2_w1' = q10_h1_r29,
        'print_days_other3_w1' = q10_h1_r30,
        'print_days_other4_w1' = q10_h1_r31,
        'print_days_other5_w1' = q10_h1_r32,
        'print_online_w1' = q11,
        'tv_tvn_w1' = q12_r1,
        'tv_tvn24_w1' = q12_r2,
        'tv_tvn24b_w1' = q12_r3,
        'tv_tr_w1' = q12_r4,
        'tv_polsat_w1' = q12_r5,
        'tv_pn_w1' = q12_r6,
        'tv_pn2_w1' = q12_r7,
        'tv_TVPInfo_w1' = q12_r8,
        'tv_TVP1_w1' = q12_r9,
        'tv_TVP2_w1' = q12_r10,
        'tv_TVP3_w1' = q12_r11,
        'tv_TVT_w1' = q12_r12,
        'tv_Superstacja_w1' = q12_r13,
        'tv_local_w1' = q12_r14,
        'tv_other_w1' = q12_r15,
        'tv_other_text1_w1' = q12inne_h1_r1,
        'tv_other_text2_w1' = q12inne_h1_r2,
        'tv_other_text3_w1' = q12inne_h1_r3,
        'tv_other_text4_w1' = q12inne_h1_r4,
        'tv_other_text5_w1' = q12inne_h1_r5,
        'tv_days_TVN_w1' = q13_h1_r1,
        'tv_days_TVN24_w1' = q13_h1_r2,
        'tv_days_TVN24B_w1' = q13_h1_r3,
        'tv_days_TR_w1' = q13_h1_r4,
        'tv_days_Polsat_w1' = q13_h1_r5,
        'tv_days_PN_w1' = q13_h1_r6,
        'tv_days_PN2_w1' = q13_h1_r7,
        'tv_days_TVPInfo_w1' = q13_h1_r8,
        'tv_days_TVP1_w1' = q13_h1_r9,
        'tv_days_TVP2_w1' = q13_h1_r10,
        'tv_days_TVP3_w1' = q13_h1_r11,
        'tv_days_TVT_w1' = q13_h1_r12,
        'tv_days_Superstacja_w1' = q13_h1_r13,
        'tv_days_local_w1' = q13_h1_r14,
        'tv_days_other1_w1' = q13_h1_r15,
        'tv_days_other2_w1' = q13_h1_r16,
        'tv_days_other3_w1' = q13_h1_r17,
        'tv_days_other4_w1' = q13_h1_r18,
        'tv_days_other5_w1' = q13_h1_r19,
        'tv_online_w1' = q14,
        'radio_other1_text_w1' = q15_h1_r1,
        'radio_other2_text_w1' = q15_h1_r2,
        'radio_other3_text_w1' = q15_h1_r3,
        'radio_other4_text_w1' = q15_h1_r4,
        'radio_other5_text_w1' = q15_h1_r5,
        'radio_days_other1_w1' = q16_h1_r1,
        'radio_days_other2_w1' = q16_h1_r2,
        'radio_days_other3_w1' = q16_h1_r3,
        'radio_days_other4_w1' = q16_h1_r4,
        'radio_days_other5_w1' = q16_h1_r5,
        'radio_online_w1' = q17,
        'webs_onet_w1' = q18_r1,
        'webs_WP_w1' = q18_r2,
        'webs_interia_w1' = q18_r3,
        'webs_o2_w1' = q18_r4,
        'webs_gazeta_w1' = q18_r5,
        'webs_natemat_w1' = q18_r6,
        'webs_wpolityce_w1' = q18_r7,
        'webs_niezalezna_w1' = q18_r8,
        'webs_krytyka_w1' = q18_r9,
        'webs_googleyahoo_w1' = q18_r10,
        'webs_foreign_w1' = q18_r11,
        'webs_polblogs_w1' = q18_r12,
        'webs_other_w1' = q18_r13,
        'webs_other_text_1_w1' = q18inne_h1_r1,
        'webs_other_text_2_w1' = q18inne_h1_r2,
        'webs_other_text_3_w1' = q18inne_h1_r3,
        'webs_other_text_4_w1' = q18inne_h1_r4,
        'webs_other_text_5_w1' = q18inne_h1_r5,
        'webs_days_onet_w1' = q19_h1_r1,
        'webs_days_WP_w1' = q19_h1_r2,
        'webs_days_interia_w1' = q19_h1_r3,
        'webs_days_o2_w1' = q19_h1_r4,
        'webs_days_gazeta_w1' = q19_h1_r5,
        'webs_days_natemat_w1' = q19_h1_r6,
        'webs_days_wpolityce_w1' = q19_h1_r7,
        'webs_days_niezalezna_w1' = q19_h1_r8,
        'webs_days_krytyka_w1' = q19_h1_r9,
        'webs_days_googleyahoo_w1' = q19_h1_r10,
        'webs_days_other1_w1' = q19_h1_r11,
        'webs_days_other2_w1' = q19_h1_r12,
        'webs_days_other3_w1' = q19_h1_r13,
        'webs_days_other4_w1' = q19_h1_r14,
        'webs_days_other5_w1' = q19_h1_r15,
        'sm_twitter_w1' = q20_r1,
        'sm_fbook_w1' = q20_r2,
        'sm_ytube_w1' = q20_r3,
        'sm_insta_w1' = q20_r4,
        'sm_snapch_w1' = q20_r5,
        'sm_tumblr_w1' = q20_r6,
        'sm_reddit_w1' = q20_r7,
        'sm_NK_w1' = q20_r8,
        'sm_other_w1' = q20_r9,
        'sm_other_text1_w1' = q20inne_h1_r1,
        'sm_other_text2_w1' = q20inne_h1_r2,
        'sm_other_text3_w1' = q20inne_h1_r3,
        'sm_other_text4_w1' = q20inne_h1_r4,
        'sm_other_text5_w1' = q20inne_h1_r5,
        'sm_days_twitter_w1' = q21_h1_r1,
        'sm_days_fbook_w1' = q21_h1_r2,
        'sm_days_ytube_w1' = q21_h1_r3,
        'sm_days_insta_w1' = q21_h1_r4,
        'sm_days_snapch_w1' = q21_h1_r5,
        'sm_days_tumblr_w1' = q21_h1_r6,
        'sm_days_reddit_w1' = q21_h1_r7,
        'sm_days_NK_w1' = q21_h1_r8,
        'sm_days_other1_w1' = q21_h1_r9,
        'sm_days_other2_w1' = q21_h1_r10,
        'sm_days_other3_w1' = q21_h1_r11,
        'sm_days_other4_w1' = q21_h1_r12,
        'sm_days_other5_w1' = q21_h1_r13,
        'attent_w1' = attn,
        'attent_text_w1' = attninne,
        'pers_issue_w1' = q23,
        'att_econ_1_w1' = q24_1_r1,
        'att_econ_2_w1' = q24_2_r1,
        'att_econ_3_w1' = q24_3_r1,
        'att_women_1_w1' = q25_1_r1,
        'att_women_2_w1' = q25_2_r1,
        'att_women_3_w1' = q25_3_r1,
        'att_relig_1_w1' = q27_1_r1,
        'att_relig_2_w1' = q27_2_r1,
        'att_relig_3_w1' = q27_3_r1,
        'att_eu_1_w1' = q28_1_r1,
        'att_eu_2_w1' = q28_2_r1,
        'att_eu_3_w1' = q28_3_r1,
        'att_welfare_1_w1' = q29_1_r1,
        'att_welfare_2_w1' = q29_2_r1,
        'att_welfare_3_w1' = q29_3_r1,
        'att_health_1_w1' = q30_1_r1,
        'att_health_2_w1' = q30_2_r1,
        'att_health_3_w1' = q30_3_r1,
        'att_crime_1_w1' = q31_1_r1,
        'att_crime_2_w1' = q31_2_r1,
        'att_crime_3_w1' = q31_3_r1,
        'att_climate_1_w1' = q33_1_r1,
        'att_climate_2_w1' = q33_2_r1,
        'att_climate_3_w1' = q33_3_r1,
        'att_lgbt_1_w1' = q34_1_r1,
        'att_lgbt_2_w1' = q34_2_r1,
        'att_lgbt_3_w1' = q34_3_r1,
        'att_immigrant_1_w1' = q35_1_r1,
        'att_immigrant_2_w1' = q35_2_r1,
        'att_immigrant_3_w1' = q35_3_r1,
        'att_immigrant_4_w1' = q35_4_r1,
        'att_justice_1_w1' = q36_1_r1,
        'att_justice_2_w1' = q36_2_r1,
        'att_justice_3_w1' = q36_3_r1,
        'att_education_1_w1' = q37_1_r1,
        'att_education_2_w1' = q37_2_r1,
        'att_education_3_w1' = q37_3_r1,
        'strong_woman_w1' = q39_r1,
        'strong_religion_w1' = q39_r2,
        'strong_foreign_w1' = q39_r3,
        'strong_econ_w1' = q39_r5,
        'strong_pers_w1' = q39_r6,
        'important_woman_w1' = q40_r1,
        'important_religion_w1' = q40_r2,
        'important_foreign_w1' = q40_r3,
        'important_econ_w1' = q40_r5,
        'important_pers_w1' = q40_r6,
        'disagr_talk_woman_w1' = q41_r1,
        'disagr_talk_religion_w1' = q41_r2,
        'disagr_talk_foreign_w1' = q41_r3,
        'disagr_talk_econ_w1' = q41_r5,
        'disagr_talk_pers_w1' = q41_r6,
        'disagr_offline_woman_w1' = q42_r1,
        'disagr_offline_religion_w1' = q42_r2,
        'disagr_offline_foreign_w1' = q42_r3,
        'disagr_offline_econ_w1' = q42_r5,
        'disagr_offline_pers_w1' = q42_r6,
        'disagr_internet_woman_w1' = q43_r1,
        'disagr_internet_religion_w1' = q43_r2,
        'disagr_internet_foreign_w1' = q43_r3,
        'disagr_internet_econ_w1' = q43_r5,
        'disagr_internet_pers_w1' = q43_r6,
        'disagr_sm_woman_w1' = q44_r1,
        'disagr_sm_religion_w1' = q44_r2,
        'disagr_sm_foreign_w1' = q44_r3,
        'disagr_sm_econ_w1' = q44_r5,
        'disagr_sm_pers_w1' = q44_r6,
        'disagr_msg_woman_w1' = q45_r1,
        'disagr_msg_religion_w1' = q45_r2,
        'disagr_msg_foreign_w1' = q45_r3,
        'disagr_msg_econ_w1' = q45_r5,
        'disagr_msg_pers_w1' = q45_r6,
        'respect_party_w1' = q46_h1_r1,
        'respect_party_opp_w1' = q46_h1_r2,
        'respect_gov_w1' = q46_h1_r3,
        'respect_opp_w1' = q46_h1_r4,
        'respect_pis_w1' = q46_h1_r5,
        'respect_sld_w2' = q46_h1_r6,
        'respect_left_w1' = q46_h1_r7,
        'respect_right_w1' = q46_h1_r8,
        'respect_women_w1' = q46_h1_r9,
        'respect_relig_w1' = q46_h1_r10,
        'respect_eu_w1' = q46_h1_r11,
        'respect_econ_w1' = q46_h1_r12,
        'respect_welfare_w1' = q46_h1_r13,
        'respect_health_w1' = q46_h1_r14,
        'respect_crime_w1' = q46_h1_r15,
        'respect_climate_w1' = q46_h1_r16,
        'respect_lgbt_w1' = q46_h1_r17,
        'respect_immigrant_w1' = q46_h1_r18,
        'respect_justice_w1' = q46_h1_r19,
        'respect_education_w1' = q46_h1_r20,
        'understand_party_w1' = q47_h1_r1,
        'understand_party_opp_w1' = q47_h1_r2,
        'understand_gov_w1' = q47_h1_r3,
        'understand_opp_w1' = q47_h1_r4,
        'understand_pis_w1' = q47_h1_r5,
        'understand_sld_w1' = q47_h1_r6,
        'understand_left_w1' = q47_h1_r7,
        'understand_right_w1' = q47_h1_r8,
        'understand_women_w1' = q47_h1_r9,
        'understand_relig_w1' = q47_h1_r10,
        'understand_eu_w1' = q47_h1_r11,
        'understand_econ_w1' = q47_h1_r12,
        'understand_welfare_w1' = q47_h1_r13,
        'understand_health_w1' = q47_h1_r14,
        'understand_crime_w1' = q47_h1_r15,
        'understand_climate_w1' = q47_h1_r16,
        'understand_lgbt_w1' = q47_h1_r17,
        'understand_immigrant_w1' = q47_h1_r18,
        'understand_justice_w1' = q47_h1_r19,
        'understand_education_w1' = q47_h1_r20,
        'ft_party_w1' = q50r1a,
        'ft_party_opp_w1' = q50r1,
        'ft_gov_w1' = q50r2,
        'ft_opp_w1' = q50r3,
        'ft_pis_w1' = q50r4,
        'ft_sld_w1' = q50r5,
        'ft_left_w1' = q50r6,
        'ft_right_w1' = q50r7,
        'ft_women_w1' = q50r8,
        'ft_relig_w1' = q50r9,
        'ft_eu_w1' = q50r10,
        'ft_econ_w1' = q50r11,
        'ft_welfare_w1' = q50r12,
        'ft_health_w1' = q50r13,
        'ft_crime_w1' = q50r14,
        'ft_climate_w1' = q50r15,
        'ft_lgbt_w1' = q50r16,
        'ft_immigrant_w1' = q50r17,
        'ft_justice_w1' = q50r18,
        'ft_education_w1' = q50r19,
        'misinfo_1_w1' = q68_r1,
        'misinfo_2_w1' = q68_r2,
        'misinfo_3_w1' = q68_r3,
        'misinfo_4_w1' = q68_r4,
        'stupid_econ_w1' = q52_1_h1_r1,
        'mean_econ_w1' = q52_1_h1_r2,
        'selfish_econ_w1' = q52_1_h1_r3,
        'stupid_relig_w1' = q52_2_h1_r1,
        'mean_relig_w1' = q52_2_h1_r2,
        'selfish_relig_w1' = q52_2_h1_r3,
        'stupid_women_w1' = q53_1_h1_r1,
        'mean_women_w1' = q53_1_h1_r2,
        'selfish_women_w1' = q53_1_h1_r3,
        'stupid_eu_w1' = q53_2_h1_r1,
        'mean_eu_w1' = q53_2_h1_r2,
        'selfish_eu_w1' = q53_2_h1_r3,
        'stupid_welfare_w1' = q54r1_h1_r1,
        'mean_welfare_w1' = q54r1_h1_r2,
        'selfish_welfare_w1' = q54r1_h1_r3,
        'stupid_health_w1' = q54r2_h1_r1,
        'mean_health_w1' = q54r2_h1_r2,
        'selfish_health_w1' = q54r2_h1_r3,
        'stupid_crime_w1' = q54r3_h1_r1,
        'mean_crime_w1' = q54r3_h1_r2,
        'selfish_crime_w1' = q54r3_h1_r3,
        'stupid_climate_w1' = q54r5_h1_r1,
        'mean_climate_w1' = q54r5_h1_r2,
        'selfish_climate_w1' = q54r5_h1_r3,
        'stupid_lgbt_w1' = q54r6_h1_r1,
        'mean_lgbt_w1' = q54r6_h1_r2,
        'selfish_lgbt_w1' = q54r6_h1_r3,
        'stupid_immigrant_w1' = q54r7_h1_r1,
        'mean_immigrant_w1' = q54r7_h1_r2,
        'selfish_immigrant_w1' = q54r7_h1_r3,
        'stupid_justice_w1' = q54r8_h1_r1,
        'mean_justice_w1' = q54r8_h1_r2,
        'selfish_justice_w1' = q54r8_h1_r3,
        'stupid_education_w1' = q54r9_h1_r1,
        'mean_education_w1' = q54r9_h1_r2,
        'selfish_education_w1' = q54r9_h1_r3,
        'stupid_opp_w1' = q55a_h1_r1,
        'mean_opp_w1' = q55a_h1_r2,
        'selfish_opp_w1' = q55a_h1_r3,
        'talk_opp_w1' = q56a_h1_r1,
        'findout_opp_w1' = q56a_h1_r2,
        'spendtime_opp_w1' = q56a_h1_r3,
        'stupid_gov_w1' = q55b_h1_r1,
        'mean_gov_w1' = q55b_h1_r2,
        'selfish_gov_w1' = q55b_h1_r3,
        'talk_gov_w1' = q56b_h1_r1,
        'findout_gov_w1' = q56b_h1_r2,
        'spendtime_gov_w1' = q56b_h1_r3,
        'stupid_party_opp_w1' = q55c_h1_r1,
        'mean_party_opp_w1' = q55c_h1_r2,
        'selfish_party_opp_w1' = q55c_h1_r3,
        'talk_party_opp_w1' = q56c_h1_r1,
        'findout_party_opp_w1' = q56c_h1_r2,
        'spendtime_party_opp_w1' = q56c_h1_r3,
        'similar_opp_woman_w1' = q57a_r1,
        'similar_opp_relig_w1' = q57a_r2,
        'similar_opp_eu_w1' = q57a_r3,
        'similar_opp_econ_w1' = q57a_r5,
        'similar_opp_pers_w1' = q57a_r6,
        'similar_gov_woman_w1' = q57b_r1,
        'similar_gov_relig_w1' = q57b_r2,
        'similar_gov_eu_w1' = q57b_r3,
        'similar_gov_econ_w1' = q57b_r5,
        'similar_gov_pers_w1' = q57b_r6,
        'norm_openness_gov_w1' = q58zw_1_r1,
        'malvol_gov_1_w1' = q58zw_1_r2,
        'malvol_gov_2_w1' = q58zw_1_r3,
        'malvol_gov_3_w1' = q58zw_1_r4,
        'malvol_gov_4_w1' = q58zw_1_r5,
        'malvol_gov_5_w1' = q58zw_1_r6,
        'norm_openness_opp_w1' = q58op_1_r1,
        'malvol_opp_1_w1' = q58op_1_r2,
        'malvol_opp_2_w1' = q58op_1_r3,
        'malvol_opp_3_w1' = q58op_1_r4,
        'malvol_opp_4_w1' = q58op_1_r5,
        'malvol_opp_5_w1' = q58op_1_r6,
        'percent_this_comp_w1' = q70_h1_r1,
        'percent_other_comp_w1' = q70_h1_r2,
        'percent_phone_w1' = q70_h1_r3,
        'percent_tablet_w1' = q70_h1_r4,
        'survey_interested_w1' = zak1_r1,
        'survey_comments_w1' = zak2,
        'meta_spr_w1' = spr) %>%
    
    # Msinformation endorsement
      mutate(
        across(starts_with("misinfo_"),
               ~ case_when(. == 1 ~ 1, . == 2 ~ 2, . == 3 ~ 4, 
                           . == 4 ~ 5, . == 5 ~ 3))) %>%
    
    # Dates
    mutate(start_date_w1 = as.POSIXct(
      start_date_w1, format = "\"%Y-%m-%d %H:%M:%S\"", tz = "CET")) %>%
    
    # Drop unncessary variables
    select(-c(q58_2_r1, q58_2_r2, q58_2_r3, q58_2_r4, q58_2_r5,
              q58_2b_r2, q58_2b_r3, q58_2b_r4, q58_2b_r5, q58_2b_r6))
  
  return(data)
}

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# W2 recoding ####
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  
recode_PL_w2 <- function(data) {
  
  data <- data %>%
    
    dplyr::rename(
      'respondent_id_w2' = respondent_id,
      'end_date_w2' = survey_finish_time,
      'start_date_w2' = survey_start_time,
      'intro_w2' = intro22222,
      'int_travel_w2' = e1_r1,
      'int_politics_w2' = e1_r2,
      'int_sports_w2' = e1_r3,
      'int_tv_w2' = e1_r4,
      'int_vgames_w2' = e1_r5,
      'int_health_w2' = e1_r6,
      'int_opentopic_w2' = e1open,
      'nfcog_1_w2' = cog_r1,
      'nfcog_2_w2' = cog_r2,
      'nfcog_3_w2' = cog_r3,
      'nfcog_4_w2' = cog_r4,
      'nfcog_5_w2' = cog_r5,
      'nfcog_6_w2' = cog_r6,
      'defconf_1_w2' = def_r1,
      'defconf_2_w2' = def_r2,
      'defconf_3_w2' = def_r3,
      'defconf_4_w2' = def_r4,
      'defconf_5_w2' = def_r5,
      'polknow_1_w2' = know_r1,
      'polknow_2_w2' = know_r2,
      'polknow_3_w2' = know_r3,
      'polknow_4_w2' = know_r4,
      'polknow_5_w2' = know_r5,
      'ideo_w2' = qq2_r1,
      'gov_suppopp_w2' = qq2dwa_r1,
      'gov_opp_1_w2' = qq3_1_h1_r1,
      'gov_opp_2_w2' = qq3_1_h1_r2,
      'gov_opp_3_w2' = qq3_1_h1_r3,
      'gov_opp_4_w2' = qq3_1_h1_r4,
      'gov_supp_1_w2' = qq3_2_h1_r1,
      'gov_supp_2_w2' = qq3_2_h1_r2,
      'gov_supp_3_w2' = qq3_2_h1_r3,
      'gov_supp_4_w2' = qq3_2_h1_r4,
      'gov_ind_1_w2' = qq3_3_h1_r1,
      'gov_ind_2_w2' = qq3_3_h1_r2,
      'gov_ind_3_w2' = qq3_3_h1_r3,
      'gov_ind_4_w2' = qq3_3_h1_r4,
      'party_w2' = qq4pref,
      'party_closeness_w2' = qq4prefjakbliska,
      'party_opp_w2' = qq4niepref,
      'approve_gov_w2' = qqrzad5,
      'days_week_tv_w2' = qq8_h2_r1,
      'days_week_print_w2' = qq8_h2_r2,
      'days_week_radio_w2' = qq8_h2_r3,
      'days_week_web_w2' = qq8_h2_r4,
      'days_week_sm_w2' = qq8_h2_r5,
      'days_week_msg_w2' = qq8_h2_r6,
      'days_week_f2f_w2' = qq8_h2_r7,
      'days_week_app_w2' = qq8_h2_r8,
      'days_week_search_w2' = qq8_h2_r9,
      'days_week_change_w2' = qq9czyzmienilo,
      'newsdiet_ideo_w2' = f1,
      'attent_w2' = qqattn,
      'attent_text_w2' = qqattninne,
      'att_econ_1_w2' = v2q24_1_r1,
      'att_econ_2_w2' = v2q24_2_r1,
      'att_econ_3_w2' = v2q24_3_r1,
      'att_women_1_w2' = v2q25_1_r1,
      'att_women_2_w2' = v2q25_2_r1,
      'att_women_3_w2' = v2q25_3_r1,
      'att_relig_1_w2' = v2q27_1_r1,
      'att_relig_2_w2' = v2q27_2_r1,
      'att_relig_3_w2' = v2q27_3_r1,
      'att_eu_1_w2' = v2q28_1_r1,
      'att_eu_2_w2' = v2q28_2_r1,
      'att_eu_3_w2' = v2q28_3_r1,
      'att_welfare_1_w2' = v2q29_1_r1,
      'att_welfare_2_w2' = v2q29_2_r1,
      'att_welfare_3_w2' = v2q29_3_r1,
      'att_health_1_w2' = v2q30_1_r1,
      'att_health_2_w2' = v2q30_2_r1,
      'att_health_3_w2' = v2q30_3_r1,
      'att_crime_1_w2' = v2q31_1_r1,
      'att_crime_2_w2' = v2q31_2_r1,
      'att_crime_3_w2' = v2q31_3_r1,
      'att_climate_1_w2' = v2q33_1_r1,
      'att_climate_2_w2' = v2q33_2_r1,
      'att_climate_3_w2' = v2q33_3_r1,
      'att_lgbt_1_w2' = v2q34_1_r1,
      'att_lgbt_2_w2' = v2q34_2_r1,
      'att_lgbt_3_w2' = v2q34_3_r1,
      'att_immigrant_1_w2' = v2q35_1_r1,
      'att_immigrant_2_w2' = v2q35_2_r1,
      'att_immigrant_3_w2' = v2q35_3_r1,
      'att_immigrant_4_w2' = v2q35_4_r1,
      'att_justice_1_w2' = v2q36_1_r1,
      'att_justice_2_w2' = v2q36_2_r1,
      'att_justice_3_w2' = v2q36_3_r1,
      'att_education_1_w2' = v2q37_1_r1,
      'att_education_2_w2' = v2q37_2_r1,
      'att_education_3_w2' = v2q37_3_r1,
      'strong_woman_w2' = qq39_r1,
      'strong_religion_w2' = qq39_r2,
      'strong_foreign_w2' = qq39_r3,
      'strong_econ_w2' = qq39_r5,
      'strong_pers_w2' = qq39_r6,
      'important_woman_w2' = qq40_r1,
      'important_religion_w2' = qq40_r2,
      'important_foreign_w2' = qq40_r3,
      'important_econ_w2' = qq40_r5,
      'important_pers_w2' = qq40_r6,
      'disagr_talk_w2' = qq41_r1,
      'disagr_msg_w2' = qq41_r2,
      'disagr_offline_w2' = qq41_r3,
      'disagr_sm_w2' = qq41_r4,
      'disagr_internet_w2' = qq41_r5,
      'understand_party_w2' = qq47_h1_r1,
      'understand_party_opp_w2' = qq47_h1_r2,
      'understand_gov_w2' = qq47_h1_r3,
      'understand_opp_w2' = qq47_h1_r4,
      'understand_pis_w2' = qq47_h1_r5,
      'understand_sld_w2' = qq47_h1_r6,
      'understand_left_w2' = qq47_h1_r7,
      'understand_right_w2' = qq47_h1_r8,
      'understand_women_w2' = qq47_h1_r9,
      'understand_relig_w2' = qq47_h1_r10,
      'understand_eu_w2' = qq47_h1_r11,
      'understand_econ_w2' = qq47_h1_r12,
      'understand_welfare_w2' = qq47_h1_r13,
      'understand_health_w2' = qq47_h1_r14,
      'understand_crime_w2' = qq47_h1_r15,
      'understand_climate_w2' = qq47_h1_r16,
      'understand_lgbt_w2' = qq47_h1_r17,
      'understand_immigrant_w2' = qq47_h1_r18,
      'understand_justice_w2' = qq47_h1_r19,
      'understand_education_w2' = qq47_h1_r20,
      'ft_party_w2' = qq50r1a,
      'ft_party_opp_w2' = qq50r1,
      'ft_gov_w2' = qq50r2,
      'ft_opp_w2' = qq50r3,
      'ft_pis_w2' = qq50r4,
      'ft_sld_w2' = qq50r5,
      'ft_left_w2' = qq50r6,
      'ft_right_w2' = qq50r7,
      'ft_women_w2' = qq50r8,
      'ft_relig_w2' = qq50r9,
      'ft_eu_w2' = qq50r10,
      'ft_econ_w2' = qq50r11,
      'ft_welfare_w2' = qq50r12,
      'ft_health_w2' = qq50r13,
      'ft_crime_w2' = qq50r14,
      'ft_climate_w2' = qq50r15,
      'ft_lgbt_w2' = qq50r16,
      'ft_immigrant_w2' = qq50r17,
      'ft_justice_w2' = qq50r18,
      'ft_education_w2' = qq50r19,
      'stupid_econ_w2' = qq52_1_h1_r1,
      'mean_econ_w2' = qq52_1_h1_r2,
      'selfish_econ_w2' = qq52_1_h1_r3,
      'stupid_relig_w2' = qq52_2_h1_r1,
      'mean_relig_w2' = qq52_2_h1_r2,
      'selfish_relig_w2' = qq52_2_h1_r3,
      'stupid_women_w2' = qq53_1_h1_r1,
      'mean_women_w2' = qq53_1_h1_r2,
      'selfish_women_w2' = qq53_1_h1_r3,
      'stupid_eu_w2' = qq53_2_h1_r1,
      'mean_eu_w2' = qq53_2_h1_r2,
      'selfish_eu_w2' = qq53_2_h1_r3,
      'stupid_welfare_w2' = qq54r1_h1_r1,
      'mean_welfare_w2' = qq54r1_h1_r2,
      'selfish_welfare_w2' = qq54r1_h1_r3,
      'stupid_health_w2' = qq54r2_h1_r1,
      'mean_health_w2' = qq54r2_h1_r2,
      'selfish_health_w2' = qq54r2_h1_r3,
      'stupid_crime_w2' = qq54r3_h1_r1,
      'mean_crime_w2' = qq54r3_h1_r2,
      'selfish_crime_w2' = qq54r3_h1_r3,
      'stupid_climate_w2' = qq54r5_h1_r1,
      'mean_climate_w2' = qq54r5_h1_r2,
      'selfish_climate_w2' = qq54r5_h1_r3,
      'stupid_lgbt_w2' = qq54r6_h1_r1,
      'mean_lgbt_w2' = qq54r6_h1_r2,
      'selfish_lgbt_w2' = qq54r6_h1_r3,
      'stupid_immigrant_w2' = qq54r7_h1_r1,
      'mean_immigrant_w2' = qq54r7_h1_r2,
      'selfish_immigrant_w2' = qq54r7_h1_r3,
      'stupid_justice_w2' = qq54r8_h1_r1,
      'mean_justice_w2' = qq54r8_h1_r2,
      'selfish_justice_w2' = qq54r8_h1_r3,
      'stupid_education_w2' = qq54r9_h1_r1,
      'mean_education_w2' = qq54r9_h1_r2,
      'selfish_education_w2' = qq54r9_h1_r3,
      'stupid_opp_w2' = qq55a_h1_r1,
      'mean_opp_w2' = qq55a_h1_r2,
      'selfish_opp_w2' = qq55a_h1_r3,
      'socdis_opp_w2' = qq55_2a_r1,
      'talk_opp_w2' = qq56a_h1_r1,
      'findout_opp_w2' = qq56a_h1_r2,
      'spendtime_opp_w2' = qq56a_h1_r3,
      'stupid_gov_w2' = qq55b_h1_r1,
      'mean_gov_w2' = qq55b_h1_r2,
      'selfish_gov_w2' = qq55b_h1_r3,
      'socdis_gov_w2' = qq55_2b_r1,
      'talk_gov_w2' = qq56b_h1_r1,
      'findout_gov_w2' = qq56b_h1_r2,
      'spendtime_gov_w2' = qq56b_h1_r3,
      'similar_opp_woman_w2' = qq57a_r1,
      'similar_opp_relig_w2' = qq57a_r2,
      'similar_opp_eu_w2' = qq57a_r3,
      'similar_opp_econ_w2' = qq57a_r5,
      'similar_opp_pers_w2' = qq57a_r6,
      'similar_gov_woman_w2' = qq57b_r1,
      'similar_gov_relig_w2' = qq57b_r2,
      'similar_gov_eu_w2' = qq57b_r3,
      'similar_gov_econ_w2' = qq57b_r5,
      'similar_gov_pers_w2' = qq57b_r6,
      'stupid_party_opp_w2' = qq55c_h1_r1,
      'mean_party_opp_w2' = qq55c_h1_r2,
      'selfish_party_opp_w2' = qq55c_h1_r3,
      'socdis_party_opp_w2' = qq55_2c_r1,
      'talk_party_opp_w2' = qq56c_h1_r1,
      'findout_party_opp_w2' = qq56c_h1_r2,
      'spendtime_party_opp_w2' = qq56c_h1_r3,
      'similar_party_woman_w2' = perdiff_r1,
      'similar_party_relig_w2' = perdiff_r2,
      'similar_party_eu_w2' = perdiff_r3,
      'similar_party_econ_w2' = perdiff_r4,
      'similar_party_pers_w2' = perdiff_r5,
      'trust_gov_w2' = qq61_r1,
      'trust_police_w2' = qq61_r2,
      'trust_media_w2' = qq61_r3,
      'trust_scourt_w2' = qq61_r4,
      'trust_church_w2' = qq61_r5,
      'supp_compr_1_w2' = compromise1_r1,
      'supp_compr_2_w2' = compromise2_r1,
      'supp_compr_3_w2' = compromise3_r1,
      'supp_compr_4_w2' = compromise4_r1,
      'malvol_gov_1_w2' = qq58zw_1_r2,
      'malvol_gov_2_w2' = qq58zw_1_r3,
      'malvol_gov_3_w2' = qq58zw_1_r4,
      'malvol_gov_4_w2' = qq58zw_1_r5,
      'malvol_gov_5_w2' = qq58zw_1_r6,
      'malvol_opp_1_w2' = qq58op_1_r2,
      'malvol_opp_2_w2' = qq58op_1_r3,
      'malvol_opp_3_w2' = qq58op_1_r4,
      'malvol_opp_4_w2' = qq58op_1_r5,
      'malvol_opp_5_w2' = qq58op_1_r6,
      'perpol_1_w2' = qq58_2_r2,
      'perpol_2_w2' = qq58_2_r3,
      'perpol_3_w2' = qq58_2_r4,
      'perpol_4_w2' = qq58_2_r5,
      'int_news_1_w2' = interest_r1,
      'int_news_2_w2' = interest_r2,
      'int_news_3_w2' = interest_r3,
      'change_int_w2' = interest5years,
      'change_int_text_w2' = interest5yearstext,
      'voted_w2' = glosowanie,
      'vote_pis_w2' = votepartyifyes_r1,
      'vote_psl_w2' = votepartyifyes_r2,
      'vote_wolnosc_w2' = votepartyifyes_r3,
      'vote_kukiz15_w2' = votepartyifyes_r4,
      'vote_po_w2' = votepartyifyes_r5,
      'vote_Nowoczesna_w2' = votepartyifyes_r6,
      'vote_sld_w2' = votepartyifyes_r7,
      'vote_PartiaRazem_w2' = votepartyifyes_r8,
      'vote_Wiosna_w2' = votepartyifyes_r9,
      'embed_vote_pis_w2' = votepis,
      'part_petition_w2' = particip_r1,
      'part_donate_w2' = particip_r2,
      'part_share_w2' = particip_r3,
      'part_hearing_w2' = particip_r4,
      'part_demo_w2' = particip_r5,
      'part_contact_w2' = particip_r6,
      'part_volunt_w2' = particip_r7,
      'part_media_w2' = particip_r8,
      'part_none_w2' = particip_r98,
      'conflict_part_1_w2' = q349_r1,
      'conflict_part_2_w2' = q349_r2,
      'conflict_part_3_w2' = q349_r3,
      'change_part_w2' = interest5years2,
      'change_part_text_w2' = interest5yearstext2,
      'polknow_prime_w2' = wiedza1,
      'polknow_head_w2' = wiedza2,
      'polknow_threshold_w2' = wiedza3,
      'polknow_rights_w2' = wiedza4,
      'misinfo_1_w2' = qq68_r1,
      'misinfo_2_w2' = qq68_r2,
      'misinfo_3_w2' = qq68_r3,
      'misinfo_4_w2' = qq68_r4,
      'twitter_account_w2' = tw1,
      'twitter_name_w2' = tw3,
      'twitter_consent_w2' = tw7,
      'percent_this_comp_w2' = qq70_h1_r1,
      'percent_other_comp_w2' = qq70_h1_r2,
      'percent_phone_w2' = qq70_h1_r3,
      'percent_tablet_w2' = qq70_h1_r4,
      'exp_ctl_w2' = wave2kontrolna,
      'exp_ctl_consent_w2' = wave2kontrolna1,
      'exp_treat_w2' = wave2eksperymentalna,
      'exp_treat_consent_w2' = wave2eksperymentalna1,
      'survey_interested_w2' = qqzak1_r1,
      'survey_comments_w2' = qqzak2) %>%
    
    # Misinformation endorsement
    mutate(
      across(starts_with("misinfo_"),
             ~ case_when(. == 1 ~ 1, . == 2 ~ 2, . == 3 ~ 4, 
                         . == 4 ~ 5, . == 5 ~ 3))) %>%
    
    # Dates
    mutate(start_date_w2 = as.POSIXct(
      start_date_w2, format = "\"%Y-%m-%d %H:%M:%S\"", tz = "CET"))
    
    return(data)
}

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# W3 recoding ####
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

recode_PL_w3 <- function(data) {
  
  data <- data %>%
    
    # Rename variables according to Codebook
    dplyr::rename(
      'respondent_id_w3' = respondent_id,
      'meta_externalid_w3' = ext_id,
      'end_date_w3' = survey_finish_time,
      'start_date_w3' = survey_start_time,
      'intro_1_w3' = intro3333,
      'intro_2_w3' = intro33333,
      'follow_w3' = med1,
      'days_week_tv_w3' = qqq8_h2_r1,
      'days_week_print_w3' = qqq8_h2_r2,
      'days_week_radio_w3' = qqq8_h2_r3,
      'days_week_web_w3' = qqq8_h2_r4,
      'days_week_sm_w3' = qqq8_h2_r5,
      'days_week_msg_w3' = qqq8_h2_r6,
      'days_week_f2f_w3' = qqq8_h2_r7,
      'days_week_app_w3' = qqq8_h2_r8,
      'days_week_search_w3' = qqq8_h2_r9,
      'polknow_imp_tv_w3' = newsimp_h1_r1,
      'polknow_imp_print_w3' = newsimp_h1_r2,
      'polknow_imp_radio_w3' = newsimp_h1_r3,
      'polknow_imp_web_w3' = newsimp_h1_r4,
      'polknow_imp_sm_w3' = newsimp_h1_r5,
      'polknow_imp_msg_w3' = newsimp_h1_r6,
      'polknow_imp_f2f_w3' = newsimp_h1_r7,
      'polknow_imp_app_w3' = newsimp_h1_r8,
      'polknow_imp_search_w3' = newsimp_h1_r9,
      'change_tv_1_w3' = newschangetv1,
      'change_tv_2_w3' = newschangetv2,
      'change_print_1_w3' = newschangeprint1,
      'change_print_2_w3' = newschangeprint2,
      'change_radio_1_w3' = newschangeradio1,
      'change_radio_2_w3' = newschangeradio2,
      'change_web_1_w3' = newschangeweb1,
      'change_web_2_w3' = newschangeweb2,
      'change_sm_1_w3' = newschangesocial1,
      'change_sm_2_w3' = newschangesocial2,
      'change_msg_1_w3' = newschangemsg1,
      'change_msg_2_w3' = newschangemsg2,
      'change_app_1_w3' = newschangeapp1,
      'change_app_2_w3' = newschangeapp2,
      'newsdiet_ideo_w3' = f1wav3,
      'selexpo_1_w3' = sel1_r1,
      'selexpo_2_w3' = sel1_r2,
      'selexpo_3_w3' = sel1_r3,
      'selexpo_4_w3' = sel1_r4,
      'selexpo_5_w3' = sel1_r5,
      'int_politics_w3' = pol_int_r1,
      'ideo_w3' = qqq2_r1,
      'gov_suppopp_w3' = qqq2dwa_r1,
      'gov_opp_1_w3' = qqq3_1_h1_r1,
      'gov_opp_2_w3' = qqq3_1_h1_r2,
      'gov_opp_3_w3' = qqq3_1_h1_r3,
      'gov_opp_4_w3' = qqq3_1_h1_r4,
      'gov_supp_1_w3' = qqq3_2_h1_r1,
      'gov_supp_2_w3' = qqq3_2_h1_r2,
      'gov_supp_3_w3' = qqq3_2_h1_r3,
      'gov_supp_4_w3' = qqq3_2_h1_r4,
      'gov_ind_1_w3' = qqq3_3_h1_r1,
      'gov_ind_2_w3' = qqq3_3_h1_r2,
      'gov_ind_3_w3' = qqq3_3_h1_r3,
      'gov_ind_4_w3' = qqq3_3_h1_r4,
      'party_w3' = qqq4pref,
      'party_closeness_w3' = qqq4prefjakbliska,
      'party_opp_w3' = qqq4niepref,
      'att_econ_1_w3' = v3q24_1_r1,
      'att_econ_2_w3' = v3q24_2_r1,
      'att_econ_3_w3' = v3q24_3_r1,
      'att_women_1_w3' = v3q25_1_r1,
      'att_women_2_w3' = v3q25_2_r1,
      'att_women_3_w3' = v3q25_3_r1,
      'att_relig_1_w3' = v3q27_1_r1,
      'att_relig_2_w3' = v3q27_2_r1,
      'att_relig_3_w3' = v3q27_3_r1,
      'att_eu_1_w3' = v3q28_1_r1,
      'att_eu_2_w3' = v3q28_2_r1,
      'att_eu_3_w3' = v3q28_3_r1,
      'att_welfare_1_w3' = v3q29_1_r1,
      'att_welfare_2_w3' = v3q29_2_r1,
      'att_welfare_3_w3' = v3q29_3_r1,
      'att_health_1_w3' = v3q30_1_r1,
      'att_health_2_w3' = v3q30_2_r1,
      'att_health_3_w3' = v3q30_3_r1,
      'att_crime_1_w3' = v3q31_1_r1,
      'att_crime_2_w3' = v3q31_2_r1,
      'att_crime_3_w3' = v3q31_3_r1,
      'att_climate_1_w3' = v3q33_1_r1,
      'att_climate_2_w3' = v3q33_2_r1,
      'att_climate_3_w3' = v3q33_3_r1,
      'att_lgbt_1_w3' = v3q34_1_r1,
      'att_lgbt_2_w3' = v3q34_2_r1,
      'att_lgbt_3_w3' = v3q34_3_r1,
      'att_immigrant_1_w3' = v3q35_1_r1,
      'att_immigrant_2_w3' = v3q35_2_r1,
      'att_immigrant_3_w3' = v3q35_3_r1,
      'att_immigrant_4_w3' = v3q35_4_r1,
      'att_justice_1_w3' = v3q36_1_r1,
      'att_justice_2_w3' = v3q36_2_r1,
      'att_justice_3_w3' = v3q36_3_r1,
      'att_education_1_w3' = v3q37_1_r1,
      'att_education_2_w3' = v3q37_2_r1,
      'att_education_3_w3' = v3q37_3_r1,
      'strong_woman_w3' = qqq39_r1,
      'strong_religion_w3' = qqq39_r2,
      'strong_foreign_w3' = qqq39_r3,
      'strong_econ_w3' = qqq39_r5,
      'strong_pers_w3' = qqq39_r6,
      'important_woman_w3' = qqq40_r1,
      'important_religion_w3' = qqq40_r2,
      'important_foreign_w3' = qqq40_r3,
      'important_econ_w3' = qqq40_r5,
      'important_pers_w3' = qqq40_r6,
      'disagr_talk_w3' = qqq41_r1,
      'disagr_msg_w3' = qqq41_r2,
      'disagr_offline_w3' = qqq41_r3,
      'disagr_sm_w3' = qqq41_r4,
      'disagr_internet_w3' = qqq41_r5,
      'understand_party_w3' = qqq47_h1_r1,
      'understand_party_opp_w3' = qqq47_h1_r2,
      'understand_gov_w3' = qqq47_h1_r3,
      'understand_opp_w3' = qqq47_h1_r4,
      'understand_pis_w3' = qqq47_h1_r5,
      'understand_sld_w3' = qqq47_h1_r6,
      'understand_left_w3' = qqq47_h1_r7,
      'understand_right_w3' = qqq47_h1_r8,
      'understand_women_w3' = qqq47_h1_r9,
      'understand_relig_w3' = qqq47_h1_r10,
      'understand_eu_w3' = qqq47_h1_r11,
      'understand_econ_w3' = qqq47_h1_r12,
      'understand_welfare_w3' = qqq47_h1_r13,
      'understand_health_w3' = qqq47_h1_r14,
      'understand_crime_w3' = qqq47_h1_r15,
      'understand_climate_w3' = qqq47_h1_r16,
      'understand_lgbt_w3' = qqq47_h1_r17,
      'understand_immigrant_w3' = qqq47_h1_r18,
      'understand_justice_w3' = qqq47_h1_r19,
      'understand_education_w3' = qqq47_h1_r20,
      'ft_party_w3' = qqq50r1a,
      'ft_party_opp_w3' = qqq50r1,
      'ft_gov_w3' = qqq50r2,
      'ft_opp_w3' = qqq50r3,
      'ft_pis_w3' = qqq50r4,
      'ft_sld_w3' = qqq50r5,
      'ft_left_w3' = qqq50r6,
      'ft_right_w3' = qqq50r7,
      'ft_women_w3' = qqq50r8,
      'ft_relig_w3' = qqq50r9,
      'ft_eu_w3' = qqq50r10,
      'ft_econ_w3' = qqq50r11,
      'ft_welfare_w3' = qqq50r12,
      'ft_health_w3' = qqq50r13,
      'ft_crime_w3' = qqq50r14,
      'ft_climate_w3' = qqq50r15,
      'ft_lgbt_w3' = qqq50r16,
      'ft_immigrant_w3' = qqq50r17,
      'ft_justice_w3' = qqq50r18,
      'ft_education_w3' = qqq50r19,
      'stupid_econ_w3' = qqq52_1_h1_r1,
      'mean_econ_w3' = qqq52_1_h1_r2,
      'selfish_econ_w3' = qqq52_1_h1_r3,
      'stupid_relig_w3' = qqq52_2_h1_r1,
      'mean_relig_w3' = qqq52_2_h1_r2,
      'selfish_relig_w3' = qqq52_2_h1_r3,
      'stupid_women_w3' = qqq53_1_h1_r1,
      'mean_women_w3' = qqq53_1_h1_r2,
      'selfish_women_w3' = qqq53_1_h1_r3,
      'stupid_eu_w3' = qqq53_2_h1_r1,
      'mean_eu_w3' = qqq53_2_h1_r2,
      'selfish_eu_w3' = qqq53_2_h1_r3,
      'stupid_welfare_w3' = qqq54r1_h1_r1,
      'mean_welfare_w3' = qqq54r1_h1_r2,
      'selfish_welfare_w3' = qqq54r1_h1_r3,
      'stupid_health_w3' = qqq54r2_h1_r1,
      'mean_health_w3' = qqq54r2_h1_r2,
      'selfish_health_w3' = qqq54r2_h1_r3,
      'stupid_crime_w3' = qqq54r3_h1_r1,
      'mean_crime_w3' = qqq54r3_h1_r2,
      'selfish_crime_w3' = qqq54r3_h1_r3,
      'stupid_climate_w3' = qqq54r5_h1_r1,
      'mean_climate_w3' = qqq54r5_h1_r2,
      'selfish_climate_w3' = qqq54r5_h1_r3,
      'stupid_lgbt_w3' = qqq54r6_h1_r1,
      'mean_lgbt_w3' = qqq54r6_h1_r2,
      'selfish_lgbt_w3' = qqq54r6_h1_r3,
      'stupid_immigrant_w3' = qqq54r7_h1_r1,
      'mean_immigrant_w3' = qqq54r7_h1_r2,
      'selfish_immigrant_w3' = qqq54r7_h1_r3,
      'stupid_justice_w3' = qqq54r8_h1_r1,
      'mean_justice_w3' = qqq54r8_h1_r2,
      'selfish_justice_w3' = qqq54r8_h1_r3,
      'stupid_education_w3' = qqq54r9_h1_r1,
      'mean_education_w3' = qqq54r9_h1_r2,
      'selfish_education_w3' = qqq54r9_h1_r3,
      'stupid_opp_w3' = qqq55a_h1_r1,
      'mean_opp_w3' = qqq55a_h1_r2,
      'selfish_opp_w3' = qqq55a_h1_r3,
      'socdis_opp_w3' = qqq55_2a_r1,
      'stupid_gov_w3' = qqq55b_h1_r1,
      'mean_gov_w3' = qqq55b_h1_r2,
      'selfish_gov_w3' = qqq55b_h1_r3,
      'socdis_gov_w3' = qqq55_2b_r1,
      'stupid_party_opp_w3' = qqq55c_h1_r1,
      'mean_party_opp_w3' = qqq55c_h1_r2,
      'selfish_party_opp_w3' = qqq55c_h1_r3,
      'socdis_party_opp_w3' = qqq55_2c_r1,
      'stupid_left_w3' = qqq55lewica1_h1_r1,
      'mean_left_w3' = qqq55lewica1_h1_r2,
      'selfish_left_w3' = qqq55lewica1_h1_r3,
      'socdis_left_w3' = qqq55lewica2_r1,
      'stupid_right_w3' = qqq55prawica1_h1_r1,
      'mean_right_w3' = qqq55prawica1_h1_r2,
      'selfish_right_w3' = qqq55prawica1_h1_r3,
      'socdis_right_w3' = qqq55prawica2_r1,
      'trust_gov_w3' = qqq61_r1,
      'trust_police_w3' = qqq61_r2,
      'trust_media_w3' = qqq61_r3,
      'trust_scourt_w3' = qqq61_r4,
      'trust_church_w3' = qqq61_r5,
      'supp_compr_1_w3' = compromise1v3_r1,
      'supp_compr_2_w3' = compromise2v3_r1,
      'supp_compr_3_w3' = compromise3v3_r1,
      'supp_compr_4_w3' = compromise4v3_r1,
      'malvol_gov_1_w3' = qqq58zw_1_r2,
      'malvol_gov_2_w3' = qqq58zw_1_r3,
      'malvol_gov_3_w3' = qqq58zw_1_r4,
      'malvol_gov_4_w3' = qqq58zw_1_r5,
      'malvol_gov_5_w3' = qqq58zw_1_r6,
      'malvol_opp_1_w3' = qqq58op_1_r2,
      'malvol_opp_2_w3' = qqq58op_1_r3,
      'malvol_opp_3_w3' = qqq58op_1_r4,
      'malvol_opp_4_w3' = qqq58op_1_r5,
      'malvol_opp_5_w3' = qqq58op_1_r6,
      'perpol_1_w3' = qqq58_2_r2,
      'perpol_2_w3' = qqq58_2_r3,
      'perpol_3_w3' = qqq58_2_r4,
      'perpol_4_w3' = qqq58_2_r5,
      'turnout_w3' = h4glosowanie,
      'vote_pres_w3' = h4,
      'part_sign_w3' = participv3_r1,
      'part_petition_w3' = participv3_r2,
      'part_donate_w3' = participv3_r3,
      'part_share_w3' = participv3_r4,
      'part_hearing_w3' = participv3_r5,
      'part_demo_w3' = participv3_r6,
      'part_contact_w3' = participv3_r7,
      'part_volunt_w3' = participv3_r8,
      'part_media_w3' = participv3_r9,
      'part_none_w3' = participv3_r98,
      'misinfo_1_w3' = qqq68_r1,
      'misinfo_2_w3' = qqq68_r2,
      'misinfo_3_w3' = qqq68_r3,
      'misinfo_4_w3' = qqq68_r4,
      'treatment_w3' = warunek1fn_r1,
      'exp_trust_gov_w3' = exp_trust_r1,
      'exp_trust_media_w3' = exp_trust_r2,
      'exp_trust_science_w3' = exp_trust_r3,
      'exp_trust_pharma_w3' = exp_trust_r4,
      'exp_trust_security_w3' = exp_trust_r5,
      'exp_part_corona_1_w3' = EXP_PARTICIPATION_r1,
      'exp_part_corona_2_w3' = EXP_PARTICIPATION_r2,
      'exp_part_corona_3_w3' = EXP_PARTICIPATION_r3,
      'exp_part_corona_4_w3' = EXP_PARTICIPATION_r4,
      'exp_part_corona_5_w3' = EXP_PARTICIPATION_r5,
      'exp_part_corona_6_w3' = EXP_PARTICIPATION_r6,
      'exp_part_corona_7_w3' = EXP_PARTICIPATION_r7,
      'exp_part_corona_8_w3' = EXP_PARTICIPATION_r98,
      'exp_misinfo_corona_1_w3' = EXP_SPILLOVER_r1,
      'exp_misinfo_corona_2_w3' = EXP_SPILLOVER_r2,
      'exp_misinfo_corona_3_w3' = EXP_SPILLOVER_r3,
      'exp_misinfo_corona_4_w3' = EXP_SPILLOVER_r4,
      'exp_att_fakenews_1_w3' = EXP_IMP_r1,
      'exp_att_fakenews_2_w3' = EXP_IMP_r2,
      'exp_att_fakenews_3_w3' = EXP_IMP_r3,
      'exp_att_fakenews_4_w3' = EXP_IMP_r4,
      'exp_facebook_true_w3' = EXP_ACCURACY,
      'twitter_account_w3' = tw1,
      'twitter_name_w3' = tw3,
      'twitter_consent_w3' = tw7,
      'percent_this_comp_w3' = qqq70_h1_r1,
      'percent_other_comp_w3' = qqq70_h1_r2,
      'percent_phone_w3' = qqq70_h1_r3,
      'percent_tablet_w3' = qqq70_h1_r4,
      'survey_interested_w3' = qqqzak1_r1,
      'survey_comments_w3' = qqqzak2) %>%
    
    # Misinformation endorsement
    mutate(
      across(starts_with("misinfo_"),
             ~ case_when(. == 1 ~ 1, . == 2 ~ 2, . == 3 ~ 4, 
                         . == 4 ~ 5, . == 5 ~ 3))) %>%
    
    # Dates
    mutate(start_date_w3 = as.POSIXct(
      start_date_w3, format = "\"%Y-%m-%d %H:%M:%S\"", tz = "CET"))
    
    return(data)
}

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Wave joining ####
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

recode_join_PL <- function(wave1, wave2 = NULL, wave3 = NULL) {
  
  data <- recode_PL_w1(wave1)
  
  if (!is.null(wave2)) {
    wave2 <- recode_PL_w2(wave2)
    data <- data %>%
      left_join(., wave2, by = "person_id")
  }
  
  if (!is.null(wave3)) {
    wave3 <- recode_PL_w3(wave3)
    data <- data %>%
      left_join(., wave3, by = "person_id")
  }
  
  return(data)
  
}


